<?php

namespace App\Services;

use App\CodeResponse;
use App\Exceptions\BusinessException;

class BaseServices
{
    // 创建一个静态变量
    // 如果不能被实例化，这里private改为protected
    private static $instance;

    /**
     * 创建一个静态实例化函数
     * 这里必须返回static，否则代码不提示
     *
     * @return static
     */
    public static function getInstance()
    {
        if (static::$instance instanceof static) {
            return static::$instance;
        }
        static::$instance = new static();
        return static::$instance;
    }

    private function __construct()
    {

    }

    private function __clone()
    {
        // TODO: Implement __clone() method.
    }

    /**
     * @param  array  $codeResponse
     * @param  string  $info
     *
     * @return mixed
     * @throws BusinessException
     */
    public function throwBusinessException(array $codeResponse = CodeResponse::PARAM_ILLEGAL, string $info = '')
    {
        throw new BusinessException($codeResponse, $info);
    }

    /**
     * @throws BusinessException
     */
    public function throwBadArgumentValue()
    {
        $this->throwBusinessException(CodeResponse::PARAM_VALUE_ILLEGAL);
    }

    /**
     * @throws BusinessException
     */
    public function throwUpdateFail()
    {
        $this->throwBusinessException(CodeResponse::UPDATED_FAIL);
    }

}
